<template>
    <view :class="'zan-actionsheet ' + (show ? 'zan-actionsheet--show' : '')">
        <view class="mask-class zan-actionsheet__mask" @tap="onMaskClick"></view>
        <view class="container-class zan-actionsheet__container">
            <!-- 选项按钮 -->
            <zan-btn
                @btnclick="handleBtnClick($event, { index })"
                :data-index="index"
                :open-type="item.openType"
                custom-class="zan-actionsheet__btn"
                :loading="item.loading"
                v-for="(item, index) in actions"
                :key="index + -+item.name"
            >
                <!-- 自定义组件控制 slot 样式有问题，故在 slot 容器上传入 loading 信息 -->

                <view :class="'zan-actionsheet__btn-content ' + (item.loading ? 'zan-actionsheet__btn--loading' : '')">
                    <view class="zan-actionsheet__name">{{ item.name }}</view>
                    <view v-if="item.subname" class="zan-actionsheet__subname">
                        {{ item.subname }}
                    </view>
                </view>
            </zan-btn>

            <!-- 关闭按钮 -->
            <view v-if="cancelText" class="zan-actionsheet__footer">
                <zan-btn custom-class="zan-actionsheet__btn" @tap.native.stop.prevent="cancelClick">{{ cancelText }}</zan-btn>
            </view>
        </view>
    </view>
</template>

<script>
'use strict';
import zanBtn from '../btn/index';
export default {
    components: {
        zanBtn
    },
    data() {
        return {};
    },
    externalClasses: ['mask-class', 'container-class'],
    props: {
        actions: {
            type: Array,
            default: () => []
        },
        show: {
            type: Boolean,
            default: false
        },
        cancelWithMask: {
            type: Boolean,
            default: true
        },
        cancelText: {
            type: String,
            default: ''
        }
    },
    methods: {
        onMaskClick: function onMaskClick() {
            if (this.cancelWithMask) {
                this.cancelClick();
            }
        },
        cancelClick: function cancelClick() {
            this.$emit('cancel');
        },
        handleBtnClick: function handleBtnClick(_ref, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(_ref, _dataset);
            /* ---处理dataset end--- */
            var _ref$currentTarget = _ref.currentTarget;
            var currentTarget = _ref$currentTarget === undefined ? {} : _ref$currentTarget;
            var dataset = currentTarget.dataset || {};
            var index = dataset.index;
            this.$emit('actionclick', {
                detail: {
                    index: index
                }
            });
        }
    },
    created: function () {}
};
</script>
<style>
@import './index.css';
</style>
